//
//  RHMasterItemCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/12/5.
//

#import "RHMasterItemCell.h"
@interface RHMasterItemCell ()


@property (nonatomic ,strong) QMUILabel *snLab;

@property (nonatomic ,strong) QMUILabel *statusContentLab;

@property (nonatomic ,strong) UIImageView *icon;

@end
@implementation RHMasterItemCell


-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

-(void)setMasterModel:(RHDevEndPointDataModel *)masterModel
{
    _masterModel = masterModel;
    
    self.snLab.text = ValidNullDataToString(_masterModel.sn, @"--");
    
    if(_masterModel.status == 1){
        self.statusContentLab.text = @"正常".rh_localized;
        self.statusContentLab.textColor = kCOLOR_HEX(@"50D671");
    }else if(_masterModel.status == 2){
        self.statusContentLab.text = @"故障".rh_localized;
        self.statusContentLab.textColor = kCOLOR_HEX(@"E52860");
    }else if(_masterModel.status == 3){
        self.statusContentLab.text = @"告警".rh_localized;
        self.statusContentLab.textColor = kCOLOR_HEX(@"FA8D15");
    }
    
}

-(void)setupUI
{
    kWeakSelf;
    self.contentView.backgroundColor = CFTabViewBgColor;
    UIView *bgView = kView;
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(15, 15, 15, 15));
    }];
    
    _icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dev_master_icon"]];
    [bgView addSubview:_icon];
    [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kScaleW(80));
        make.left.mas_offset(kScaleW(50));
        make.centerY.mas_offset(0);
    }];
    
    _masterLab = [[QMUILabel alloc]init];
    [bgView addSubview:_masterLab];
    _masterLab.text = @"Master 1#";
    _masterLab.font = kBOLDSYSTEMFONT(16);
    _masterLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:1];
    _masterLab.textAlignment = NSTextAlignmentLeft;
    [_masterLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.icon).offset(5);
        make.left.equalTo(weakSelf.icon.mas_right).offset(kScaleW(20));
    }];
    
    QMUILabel *snTitleLab = [[QMUILabel alloc]init];
    [bgView addSubview:snTitleLab];
    snTitleLab.font = kSYSTEMFONT(12);
    snTitleLab.text = @"SN:";
    snTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    snTitleLab.textAlignment = NSTextAlignmentLeft;
    [snTitleLab sizeToFit];
    [snTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.masterLab.mas_bottom).offset(5);
        make.left.equalTo(weakSelf.masterLab);
        make.width.offset(snTitleLab.width+1);
    }];
    
    _snLab = [[QMUILabel alloc]init];
    [bgView addSubview:_snLab];
    _snLab.font = kSYSTEMFONT(12);
    _snLab.text = @"SN:1245645645";
    _snLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    _snLab.numberOfLines = 2;
    _snLab.textAlignment = NSTextAlignmentLeft;
    
    [_snLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.masterLab.mas_bottom).offset(5);
        make.left.equalTo(snTitleLab.mas_right);
        make.right.mas_offset(-3);
    }];
    
    
    
    
    QMUILabel *statusTitleLab = [[QMUILabel alloc]init];
    [bgView addSubview:statusTitleLab];
    statusTitleLab.font = kSYSTEMFONT(12);
    statusTitleLab.text = [NSString stringWithFormat:@"%@:",@"状态".rh_localized];
    statusTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:1];
    statusTitleLab.textAlignment = NSTextAlignmentLeft;
    
    [statusTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(snTitleLab.mas_bottom).offset(15);
        make.left.equalTo(weakSelf.masterLab);
    }];
    
    _statusContentLab = [[QMUILabel alloc]init];
    [bgView addSubview:_statusContentLab];
    _statusContentLab.font = kSYSTEMFONT(12);
    _statusContentLab.text = @"正常".rh_localized;
    _statusContentLab.textColor = [UIColor colorWithHexString:@"50D671" alpha:1];
    _statusContentLab.textAlignment = NSTextAlignmentLeft;
    
    [_statusContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(statusTitleLab);
        make.left.equalTo(statusTitleLab.mas_right);
    }];
}
@end
